/**
*	我的 控制器
*/
Ext.define('MyApp.controller.UserinfoController', {
	extend: 'Ext.app.Controller',
	config: {
		stores: [
			
		],
		
		models: [
			
		],
		
		views: [
			'user.User',
			'user.UserInfoList',
			'user.UserLogin',
			'user.UserRegister'
		],
		
		refs:{
			userView : 'navigationview[name=userView]',
			loginBtn : 'button[name=login]',
			regBtn : 'button[name=register]'
		},
		
		routes:{
			'user' : 'userAction',
			'login': 'loginAction'
		},
		
		
		
		control:{
			loginBtn: {
				'tap': function(t){
					
					this.overly = Ext.Viewport.add({
							xtype:'overly',
							padding: 10,
							width: 300,
							height: 210,
							name: 'login',
							items: [
								{
									docked: 'top',
									xtype: 'titlebar',
									title: '登录',
									items: [
										{
											iconCls: 'delete',
											align: 'left',
											text: '关闭',
											handler: function(btn){
												btn.up('panel').destroy();
											}
										},
										{
											iconCls: 'user',
											align: 'right',
											name: 'register',
											text: '注册'
										}
									]
								},
								{
									xtype: 'userlogin'
								}
							],
						});
					this.overly.show();
					window.location.hash = 'login';
				}
			},
			
			regBtn: {
				'tap': function(t){
					var nav = this.getUserView();
					if(nav)
					{
						nav.push({
							xtype: 'panel',
							title: '用户注册',
						width: '100%',
						name: 'register',
						padding: 0,
						border: 0,
						height: '100%',
						items: [
							/*{
								docked: 'top',
								xtype: 'titlebar',
								
								items: [
									{
										align: 'left',
										iconCls: 'delete',
										text: '关闭',
										handler: function(btn){
											//btn.up('panel').destroy();
										}
									}
								]
							},*/
							{
								xtype: 'userregister'
							}
						]
						});
					}
					if(this.overly)
					{
						this.overly.destroy();
					}
					/*this.overlyr = Ext.Viewport.add({
						xtype: 'overly',
						width: '100%',
						name: 'register',
						padding: 0,
						border: 0,
						height: '100%',
						items: [
							{
								docked: 'top',
								xtype: 'titlebar',
								title: '用户注册',
								items: [
									{
										align: 'left',
										iconCls: 'delete',
										text: '关闭',
										handler: function(btn){
											btn.up('panel').destroy();
										}
									}
								]
							},
							{
								xtype: 'userregister'
							}
						]
					});
						
					if(this.overly)
					{
						this.overly.destroy();
						this.overlyr.show();
					}
					else
					{
						this.overlyr.show();
					}*/
					window.location.hash = 'register';
				}
			}
		}
	},
	
	loginAction: function(){
		var login = Ext.Viewport.down('register');
		var nav = this.getUserView();
		if(nav)
		{
			nav.pop();
		}
	},
	
	userAction: function(){
		var login = Ext.Viewport.down('register');
		var nav = this.getUserView();
		if(nav)
		{
			nav.pop();
		}
		var overly = Ext.Viewport.down('overly');
		if(overly)
		{
			overly.destroy();
		}
	},
	
	init: function(){
		var me = this;
		me.callParent();
	}
});